Skip to content

fix(layout): place the next grid row below the tallest item - #2520

Open
MarkusAbtion wants to merge 1 commit into
Shopify:mainfrom
MarkusAbtion:fix/grid-stale-min-height-row-overlap
Open

MarkusAbtion wants to merge 1 commit into
Shopify:mainfrom
MarkusAbtion:fix/grid-stale-min-height-row-overlap

Conversation

@MarkusAbtion

Copy link
Copy Markdown

Description

Fixes #2519

In a grid, layouts are kept per index across data changes, including minHeight. When a new item at an index measures exactly its stale minHeight, processAndReturnTallestItemInRow skips it as a tallest candidate (layout.height > layout.minHeight), so a shorter item becomes tallestItem. The uneven-row branch (maxHeight - tallestItem.height > 1) then resets the min heights, but it still returned that shorter item. recomputeLayouts starts the next row at tallestItem.y + tallestItem.height, so the next row overlapped the taller items, and since nothing resizes afterwards, it stayed that way.

The fix: in that branch, return the row's tallest measured item. Only the uneven-row path changes; rows where the check already found the tallest item behave as before.

Affected package: @shopify/flash-list (GridLayoutManager).

Reviewers’ hat-rack 🎩

  • yarn jest src/__tests__/GridLayoutManager.test.ts: the new test ("should place the next row below the tallest item after data changes") fails on main with Expected: 437, Received: 408 and passes with this change.
  • Full suite (yarn test, 200 tests), yarn type-check and yarn lint pass locally.
  • Worth a look: whether returning the tallest item while minHeight is reset to 0 for the whole row interacts well with the repaint that follows. In my testing the next measurement pass keeps the row at the tallest item's height.

Screenshots or videos (if needed)

Seen on web in a 3-column grid of cards whose titles wrap to one or two lines: after a search changed data, cards with two-line titles were covered by the next row by one line height. With this change, or with clearLayoutCacheOnUpdate() called on data change as a workaround, the overlap is gone.

A stale minHeight left over from previous data could exclude the row's real
tallest item from the tallest check. The uneven-row branch then reset the
min heights but returned the shorter item, so the next row started too high
and overlapped the taller items, and nothing corrected it afterwards.

Fixes Shopify#2519

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid: next row overlaps taller items after data changes (stale minHeight picks the wrong tallest item)

1 participant